package acom.test.swing.bb;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MenuPanel extends JPanel{
	private static final long serialVersionUID = 1L;
	
	private InputDataFrame inputDataFrame;
	private SetPrizeFrame setPrizeFrame;
	
	private int position_x = 5;
	private int position_y = 5;
	
	private CardLayout cardLayout;

	private JButton menubut;
	private JPanel cardPane;
	private JPanel visiblePane;
	private JPanel hidePane;

	private JLabel add_lb;
	private JLabel set_lb;
	
	private boolean visible =false;

	public MenuPanel(){
		this.setLayout(null);
		
		ImageIcon menu_icon = SystemUtil.createImageIcon("menulogo.jpg");
		menubut = new JButton(menu_icon);
		cardPane = new JPanel();
		cardLayout = new CardLayout();
		cardPane.setLayout(cardLayout);

		visiblePane = new JPanel();
		hidePane = new JPanel();

		cardPane.add(hidePane, "hide");
		cardPane.add(visiblePane, "show");

		add_lb = new JLabel("导入名单" ,JLabel.CENTER);
		set_lb = new JLabel("奖项设置",JLabel.CENTER);
		visiblePane.setLayout(new GridLayout(2, 2));
		visiblePane.add(add_lb);
		visiblePane.add(set_lb);

		init();
		this.add(menubut);
		this.add(cardPane);
	}

	private void init() {
		this.setOpaque(false);
		menubut.setBounds(position_x, position_y, 41, 35);
		cardPane.setBounds(position_x, position_y + 36, 80, 45);
		cardPane.setOpaque(false);
		//visiblePane.setOpaque(false);
		hidePane.setOpaque(false);
				
						
		menubut.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				if(visible){
					cardLayout.show(cardPane, "hide");
					visible = false;
				}else{
					cardLayout.show(cardPane, "show");
					visible = true;
				}
				
			}
		});
		
		add_lb.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				if(inputDataFrame ==null){
					inputDataFrame = new InputDataFrame();
				}
				inputDataFrame.showFrame();
			}
		});
		
		set_lb.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				if(setPrizeFrame==null){
					setPrizeFrame = new SetPrizeFrame();
				}
				setPrizeFrame.showFrame();
			}
		});
		
		menubut.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		
		add_lb.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		set_lb.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	}
	
}
